def low_level_siptest_1():
  """Normal internal call"""
  SipPhone1.requestMakeCall(DN2.number)
  resp = SipPhone1.WaitClientEvent()
  print  ShortSipMessToString(resp)
  ev = SipPhone1.WaitServerEvent() # orig
  print  ShortSipMessToString(ev) 
  ev = SipPhone1.WaitServerEvent() # deliv
  print  ShortSipMessToString(ev)  
  ev = SipPhone2.WaitServerEvent() # deliv
  print  ShortSipMessToString(ev)
  if ev:
    callID = GetIDFromEvent("callID", ev.body)
    SipPhone2.requestAnswerCall(callID)
    resp = SipPhone2.WaitClientEvent()
    print  ShortSipMessToString(resp)
    ev = SipPhone2.WaitServerEvent() # est
    print  ShortSipMessToString(ev)
    ev = SipPhone1.WaitServerEvent() # est
    print  ShortSipMessToString(ev)
    SipPhone2.requestReleaseCall(callID)
    resp = SipPhone2.WaitClientEvent()
    print  ShortSipMessToString(resp)
    ev = SipPhone1.WaitServerEvent() # cleared
    print  ShortSipMessToString(ev)
    ev = SipPhone1.WaitServerEvent() # cleared, may be
    print ShortSipMessToString(ev)
    ev = SipPhone2.WaitServerEvent() # cleared
    print  ShortSipMessToString(ev)
    ev = SipPhone2.WaitServerEvent() # cleared, may be
    print  ShortSipMessToString(ev)
  while 1:
    ev = LocalTserver.WaitEvent(DN1.number, timeout = 2)
    if not ev:
      break
    ev = LocalTserver.WaitEvent(DN2.number, timeout = 2)
    if not ev:
      break     
      
def low_level_siptest_2():
  """Calling a really long number"""
  SipPhone1.requestMakeCall("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
  resp = SipPhone1.WaitClientEvent()
  print  ShortSipMessToString(resp)
  while 1:
    ev = SipPhone1.WaitServerEvent(timeout = 5)
    if not ev:
      break

  while 1:
    ev = LocalTserver.WaitEvent(DN1.number, timeout = 2)
    if not ev:
      break
      
def low_level_siptest_3():
  """Calling a crazy number"""
  SipPhone1.requestMakeCall("%$DE@432352&^))!~")
  resp = SipPhone1.WaitClientEvent()
  print  ShortSipMessToString(resp)
  ev = SipPhone1.WaitServerEvent() # failed
  print ShortSipMessToString(ev) 
  ev = SipPhone1.WaitServerEvent() # cleared
  print ShortSipMessToString(ev) 

  while 1:
    ev = LocalTserver.WaitEvent(DN1.number, timeout = 2)
    if not ev:
      break    
      
def low_level_siptest_4():
  """Calling non existing number"""
  SipPhone1.requestMakeCall("7777000011112222")
  resp = SipPhone1.WaitClientEvent()
  print  ShortSipMessToString(resp)
  ev = SipPhone1.WaitServerEvent() # orig
  print ShortSipMessToString(ev) 
  callID = GetIDFromEvent("callID", ev.body)
  ev = SipPhone1.WaitServerEvent() # delivered  (?? why delivered if dest busy ??)
  print ShortSipMessToString(ev) 
  ev = SipPhone1.WaitServerEvent() # failed
  print ShortSipMessToString(ev) 
  SipPhone1.requestReleaseCall(callID)  
  resp = SipPhone1.WaitClientEvent()
  print  ShortSipMessToString(resp)    
  ev = SipPhone1.WaitServerEvent() # cleared
  print ShortSipMessToString(ev) 

  while 1:
    ev = LocalTserver.WaitEvent(DN1.number, timeout = 2)
    if not ev:
      break         
      
def low_level_siptest_5():
  """Calling an empty number"""
  SipPhone1.requestMakeCall("")
  resp = SipPhone1.WaitClientEvent()
  print  ShortSipMessToString(resp)
         
      
      
def low_level_siptest_10():
  """Sending some requests twice"""
  SipPhone1.requestMakeCall(DN2.number)
  resp = SipPhone1.WaitClientEvent()
  print  ShortSipMessToString(resp)  
  ev = SipPhone1.WaitServerEvent() # orig
  print  ShortSipMessToString(ev) 
  ev = SipPhone1.WaitServerEvent() # deliv
  print  ShortSipMessToString(ev)  
  ev = SipPhone2.WaitServerEvent() # deliv
  print  ShortSipMessToString(ev)
  if ev:
    callID = GetIDFromEvent("callID", ev.body)
    SipPhone2.requestAnswerCall(callID)
    resp = SipPhone2.WaitClientEvent()
    print  ShortSipMessToString(resp)    
    SipPhone2.requestAnswerCall(callID)    
    resp = SipPhone2.WaitClientEvent() 
    print  ShortSipMessToString(resp)
    ev = SipPhone2.WaitServerEvent() # est
    print  ShortSipMessToString(ev)
    ev = SipPhone1.WaitServerEvent() # est
    print  ShortSipMessToString(ev)
    SipPhone2.requestReleaseCall(callID)
    resp = SipPhone2.WaitClientEvent()
    print  ShortSipMessToString(resp)
    SipPhone2.requestReleaseCall(callID)
    resp = SipPhone2.WaitClientEvent()
    print  ShortSipMessToString(resp)    
    ev = SipPhone1.WaitServerEvent() # cleared
    print  ShortSipMessToString(ev)
    ev = SipPhone1.WaitServerEvent() # cleared, may be
    print ShortSipMessToString(ev)
    ev = SipPhone2.WaitServerEvent() # cleared
    print  ShortSipMessToString(ev)
    ev = SipPhone2.WaitServerEvent() # cleared, may be
    print  ShortSipMessToString(ev)
  while 1:
    ev = LocalTserver.WaitEvent(DN1.number, timeout = 2)
    if not ev:
      break
    ev = LocalTserver.WaitEvent(DN2.number, timeout = 2)
    if not ev:
      break     
      